<template>
    <div class="mod_crawler_add">
        <el-dialog 
    
        :title="!dataForm.id ? '新增' : '查看'"
        :close-on-click-modal="false"
        :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" style="width:400px" label-width="80px">
        <el-form-item label="高校名" prop="teacherId">
          <el-autocomplete class="crawler_input" v-model="dataForm.from" placeholder="请输入高校名" clearable :fetch-suggestions="querySearchAsync" 
            ></el-autocomplete>
         
        </el-form-item>
        <el-form-item label="年份"  >
          <el-date-picker
          class="crawler_input"
              v-model="dataForm.time"
              type="year"
              value-format="yyyy"
              placeholder="选择年">
          </el-date-picker>
         
        </el-form-item>
       
        
       
       
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="visible = false">取消</el-button>
          <el-button type="primary" :disabled="!!level" @click="dataFormSubmit()">确定</el-button>
        </span>
      </el-dialog>
    </div>
    
  </template>
  
  <script>
  import { statisticalanalysisApi as sc } from '@/api/statisticalanalysis'
  
    export default {
      data () {
        return {
          visible: false,
          level:null,
          dataForm: {
            from: '',
            time:'',
            startData:'',
            endData: ''
          },
        
          dataRule: {
           
            from: [
              { required: true, message: '高校名不能为空', trigger: 'blur' }
            ],
            time: [
              { required: true, message: '时间不能为空', trigger: 'blur' }
            ]
          }
        }
      },
      methods: {
        init(){
            this.visible=true
            sc.schoolData().then(({name})=>{
            let data = []
            name.forEach(string => {
                data.push({value:string})
            });
            this.schools=data;
        })
        },
        querySearchAsync(queryString, cb){
            let data = this.schools.filter(({value})=>{
                return value.indexOf(queryString)>=0
            })
            cb(data)
        },
        // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm'].validate((valid) => {
            if (valid) {
                this.dataForm.startData=this.dataForm.time+'-01-01'
                this.dataForm.endData=parseInt(this.dataForm.time)+1+'-01-01'

                sc.searchData(this.dataForm)
              .then(data => {
                if (data && data.code ==20000) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            }
          })
        }
      }
    }
  </script>
  <style lang="scss">
  .mod_crawler_add{
    .crawler_input{
        width: 250px !important;
      }
      .el-dialog{
        width: 400px;
      }
  }

</style>
  